package com.kexinde.wjifen.action;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.kexinde.wjifen.dao.AddressDao;
import com.kexinde.wjifen.dao.ShopCommentViewDao;
import com.kexinde.wjifen.dao.ShopDao;
import com.kexinde.wjifen.dao.ShopProductDao;
import com.kexinde.wjifen.model.Address;
import com.kexinde.wjifen.model.Shop;
import com.kexinde.wjifen.model.ShopProduct;
import com.kexinde.wjifen.vo.ShopCommentView;
import com.opensymphony.xwork2.ActionSupport;

public class ShopDetailAction extends ActionSupport implements RequestAware,
		SessionAware, ApplicationAware {
	private final static Logger logger = Logger.getLogger(IndexAction.class);
	private Map<String, Object> request;
	private Map<String, Object> session;
	private Map<String, Object> application;
	private Long shopId;

	public String execute() {
		try {
			Shop shop = new ShopDao().findById(shopId);
			List<ShopProduct> shopProducts = new ShopProductDao().findByShopId(shopId);
			Address address = new AddressDao().findById(shop.getAddressId());
			List<ShopCommentView> shopComments = new ShopCommentViewDao().findByShopId(shopId);
			request.put("shop", shop);
			request.put("address", address);
			request.put("shopProducts", shopProducts);
			request.put("shopComments", shopComments);
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ERROR;
	}

	@Override
	public void setApplication(Map<String, Object> application) {
		this.application = application;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}


	public Long getShopId() {
		return shopId;
	}

	public void setShopId(Long shopId) {
		this.shopId = shopId;
	}

	public Map<String, Object> getRequest() {
		return request;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public Map<String, Object> getApplication() {
		return application;
	}

}
